This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
sql: use checksums to determine if indexes are outdated #583
+191
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First part of src-d/gitbase#661
After a few attempts, I've settled with this way of handling this, since this is backwards compatible, does not introduce any breaking changes and uses existing mechanisms.
Checksum is sent to the driver using the index configuration that we were not using for anything yet. Instead of changing the API of the drivers to accept a checksum, since this is more of a temporal solution until updates are supported, I preferred to use this way.
Indexes hold the checksum value inside so they can return it. An
sql.Index
may or may not implementsql.Checksumable
, which makes it really up to the driver to use checksums or not.Tables may also implement
sql.Checksumable
. If a table is not checksumable, the driver will do nothing related to checksums. If it is, when the driver is loaded it will compare both checksums and mark the index as outdated if they don't match.A new
IndexOutdated
status has been added for indexes. The index is loaded, so it can be dropped, but it can not be used in any query or overwritten before deleting it. Not loading it if it was outdated would have made it possible for multiple identical indexes to exist at the same time for different versions, which did not make much sense.When the index is marked as outdated a warning is printed.